﻿$(document).ready(function(){
	if($('#page_left').length){//有左导航
		
		$('#a_collapse').click(function(){
			if(this.src.indexOf('/images/bl_1.gif')!=-1){
				this.src='/images/al_1.gif';
				this.title='展开';
				$('#page_left').hide();
				$('#page_main').css('width','971px');
			}else{
				this.src='/images/bl_1.gif'	;
				this.title='收起';
				$('#page_left').show();
				$('#page_main').css('width','820px');
			}
		});
		
		initLeftMenu();
		
		
		$("#menu").click(function(event){
			if(event.target.tagName == "A"){
				if($(event.target).attr("href") == "#"){
					hidAllChildren();
					$(event.target).parent("li").children("ul").slideDown("slow");
				}
			}
		});
	}else{//无左导航
		$('#page_main').css('width','100%');	
	}

});

function hidAllChildren(){
	$("#menu").find("li").find("ul").hide();
}
function initLeftMenu(){
	hidAllChildren();

    $("#menu li").each(function(){
	    var bShow;
	    bShow = false;
	    $(this).find("a").each(function(){
	        if( $(this).attr("href") != "#"){
	            if( $(this).attr("display") != "none" ){
	                bShow = true;
	            }
	        }
	    });
	    if( bShow == false ){
	        $(this).hide();
	    }else{
	        $(this).show();
	    }
	});
	
	$("#menu a").each(function() {
		var aUrl = $(this).attr("href").toLower();
		var curUrl = location.href.toLower();
		curUrl = curUrl.substring(curUrl.lastIndexOf("/") + 1);
		aUrl = aUrl.substring(aUrl.lastIndexOf("/") + 1);
		
		curUrl = curUrl.replace("#","");
		if(curUrl.indexOf("?type=") == -1){
		    
		    curUrl = curUrl.replace(/\?.+/,"");
		    aUrl = aUrl.replace(/\?.+/,"");
		}
		if( curUrl==aUrl ){
	        $(this).parents("ul:first").slideDown("fast");
	        return;
	    }
	});
}